package com.qingcloud.adminbackend.controller;


import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.constant.WamingConstant;
import com.qingcloud.adminbackend.entity.sensor.CheckSensorDTO;
import com.qingcloud.adminbackend.entity.sensor.SysSensor;
import com.qingcloud.adminbackend.entity.sensor.SysSensorDTO;
import com.qingcloud.adminbackend.service.ISysSensorService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 设备传感器数据表 前端控制器
 * </p>
 *
 * @author luozehua
 * @since 2019-04-16
 */
@RestController
@RequestMapping("/sys-sensor")
public class SysSensorController {

    @Resource
    private ISysSensorService sysSensorService;

    @ApiOperation(value = "设备下传感器信息", notes = "设备下传感器信息", response = SysSensorDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipmentId", value = "设备编号", dataType = "string", paramType = "query")
    })
    @PostMapping("/sensorDetails")
    public AjaxResult sensorDetails(String equipmentId) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysSensorService.sensorDetails(equipmentId));
    }

    @ApiOperation(value = "监测传感器ID是否已经存在", notes = "监测传感器ID是否已经存在")
    @ApiImplicitParam(name = "sensorId", value = "传感器ID", dataType = "string", paramType = "path")
    @GetMapping(value = "/existId/{sensorId}")
    public AjaxResult existId(@PathVariable("sensorId") String sensorId) {
        Integer flag = sysSensorService.existId(sensorId);
        return new AjaxResult(WamingConstant.SUCCESS, "", flag);
    }

    @ApiOperation(value = "通过ID查询传感器", notes = "通过ID查询传感器")
    @ApiImplicitParam(name = "sensorId", value = "传感器ID", dataType = "string", paramType = "path")
    @GetMapping(value = "/findById/{sensorId}")
    public AjaxResult findById(@PathVariable("sensorId") String sensorId) {
        SysSensor sensor = sysSensorService.findById(sensorId);
        return new AjaxResult(WamingConstant.SUCCESS, "", sensor);
    }

    @ApiOperation(value = "通过传感器ID校验", notes = "通过传感器ID校验", response = CheckSensorDTO.class)
    @ApiImplicitParam(name = "sensorId", value = "传感器ID", dataType = "string", paramType = "path")
    @GetMapping(value = "/checkSensor/{sensorId}")
    public AjaxResult checkSensor(@PathVariable("sensorId") String sensorId) {
        return new AjaxResult(WamingConstant.SUCCESS, "", sysSensorService.checkSensor(sensorId));
    }

}

